<template>
	<view v-if="load">
		<view class="persion-line"></view>
		<view class="form-body">
			<view class="form-title">
				<view class="form-title-line"></view>
				<view class="form-title-txt">
					{{bx_id == 9 ? '充电桩清单':'投保人员'}}
				</view>
			</view>
			<view class="maxbox" v-if="bx_id != 9">
				<view class="inpbox flex-space-between">
					<input type="text" class="inpbox_inp" v-model="userconst" placeholder="请输入姓名或身份证号码" />
					<view class="sosuo" @click="search">
						搜索
					</view>
				</view>

			</view>
			<view class="persion-table persion-table-th">
				<view class="persion-table-item persion-table-index" v-if="state == 1"></view>
				<view class="persion-table-item persion-table-name">{{bx_id == 9 ? '编号':'姓名'}}</view>
				<view class="persion-table-item persion-table-idcard">{{bx_id == 9 ? '价值':'身份证号'}}</view>
			</view>
			<view class="persion-table persion-table-td" v-for="(item,index) in list" :key="'per'+index">
				<view class="persion-table-item persion-table-index" @tap="checkUser(item.id)" v-if="state == 1">
					<view class="persion-table-check-no" v-if="isCheck(item.id)"></view>
					<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/persion1.png" v-else
						class="persion-table-check"></image>
				</view>
				<view class="persion-table-item persion-table-name">{{bx_id == 9 ? item.no:item.name}}</view>
				<view class="persion-table-item persion-table-idcard">{{bx_id == 9 ? item.price:item.id_card}}</view>
			</view>
		</view>
		<view :class="state == 1 ? 'footer-box-120' : 'footer-box-20'">

		</view>
		<view class="persion-btn" style="display: flex;align-items: center" v-if='bx_id != 9'>
			<view style="width: 375upx;border-right: 2upx #ffffff solid;" @tap="changeUserModel" v-if="state == 1">批增人员
			</view>
			<view style="width: 375upx;" @tap="changeUserModel" v-if="state == 1">批改人员</view>
		</view>
		<persion-model ref="addpersons" title="替换信息" @change="addPersonConfirm"></persion-model>
	</view>
</template>

<script>
	import persionModel from '@/components/persion/persion.vue';

	export default {
		components: {
			persionModel
		},
		data() {
			return {
				id: 0,
				load: false,
				list: {},
				show: 1,
				check: -1,
				state: 0,
				ids: [],
				userconst: '',
				typeL: '',
				info: {},
				bx_id:0,
				
			}
		},
		onLoad(e) {
			this.id = e.id;
			console.log(e);
			this.typeL = e.type;
			this.getData();
		},
		methods: {
			isCheck(id) {
				var is_check = true;
				this.ids.forEach((item) => {
					if (id == item) {
						is_check = false;
					}
				})
				return is_check;
			},
			addPersonConfirm(e) {
				uni.showLoading({
					title: '提交中',
					mask: true
				})
				var id = this.list[this.check].id;
				this.ajax('user/userChange', {
					data: {
						id: id,
						name: e.name,
						id_card: e.id_card
					},
					success: (res) => {
						uni.hideLoading();
						this.toast(res.msg);
						if (res.code) {
							this.list[this.check].name = e.name;
							this.list[this.check].id_card = e.id_card;
							this.check = -1;
						}
					}
				});
			},
			changeUserModel() {
				//if(this.ids.length == 0)return this.toast('请选择要替换人员');
				uni.navigateTo({
					url: '/pages/order/change?id=' + this.id + '&ids=' + JSON.stringify(this.ids) + '&type=' + this
						.typeL
				})
			},
			checkUser(id) {
				var key = 0;
				var type = 1;
				this.ids.forEach((item, index) => {
					if (id == item) {
						type = 0;
						key = index;
					}
				})
				if (type == 1) {
					this.ids.push(id);
				} else {
					this.ids.splice(key, 1);
				}

			},
			getData() {
				uni.showLoading({
					title: '加载中'
				})
		 this.getOrderInfo()
			 
			
			
			},
			getOrderInfo() {
				this.ajax('user/orderInfo', {
					data: {
						id: this.id,
					},
					success: (res) => {
						uni.hideLoading();
				this.bx_id = res.msg.bx_id
						 if(this.bx_id == 9){
						 		this.getOrderStake()
						 }else{
						 	console.log(231);
						 	this.getOrderUser()
						 }


					}
				});
			},
			getOrderStake() {
				this.ajax('user/OrderStake', {
					data: {
						id: this.id,
						key_words: this.userconst
					},
					success: (res) => {
						uni.hideLoading();
						this.state = res.msg.state;
						this.list = res.msg.stake;
						this.load = true;
					}
				});
			},
			getOrderUser() {
				this.ajax('user/orderUser', {
					data: {
						id: this.id,
						key_words: this.userconst
					},
					success: (res) => {
						uni.hideLoading();
						this.state = res.msg.state;
						this.list = res.msg.user;
						this.load = true;
					}
				});
			},
			search() {
				this.getData()
				// uni.showLoading({
				// 	title:'加载中'
				// })
				// this.ajax('user/orderUser',{
				// 	data:{
				// 		id: this.id,
				// 		key_words:this.userconst
				// 	},
				// 	success:(res) => {
				// 		uni.hideLoading();
				// 		this.state = res.msg.state;
				// 		this.list = res.msg.user;
				// 		this.load = true;
				// 	}
				// });
			}
		}
	}
</script>

<style>
	@import url("@/static/css/box/form.css");
	@import url("@/static/css/order/persion.css");
</style>